package com.example.beanlife.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;

/**
 * ClassName:Vip
 * Package:com.example.beanlife.bean
 * Description:
 *
 * @Author:ZhangXin
 * @Create:2023/5/9-9:13
 * @Version:v1.0
 */
public class Vip implements BeanNameAware, BeanClassLoaderAware, BeanFactoryAware , InitializingBean ,DisposableBean{

    public Vip() {
        System.out.println("第一步:Bean的实例化(调用无参构造方法)");
    }

    private String name;

    public void setName(String name) {
        System.out.println("第二步:Bean的属性赋值(调用set方法)");
        this.name = name;
    }

    @Override
    public String toString() {
        return "Vip{" +
               "name='" + name + '\'' +
               '}';
    }

    public void initBean() {
        System.out.println("第四歩:初始化Bean");
    }

    public void destroyBean() {
        System.out.println("第七步:销毁bean");
    }

    @Override
    public void setBeanClassLoader(ClassLoader classLoader) {
        System.out.println("Bean这个类的加载器:" + classLoader);
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("生成Bean的工厂对象是:" + beanFactory);
    }

    @Override
    public void setBeanName(String name) {
        System.out.println("这个Bean的名字是:" + name);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("InitializingBean 的 afterPropertiesSet 方法执行 ");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("DisposableBean 的 destroy 方法执行");
    }
}
